//
//  XTCellofCellForeveryone.m
//  TTLestening
//
//  Created by dllo on 16/3/22.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "XTCellofCellForeveryone.h"
#import "XCModelForEveryone.h"
#import <SDWebImage/UIImageView+WebCache.h>
#define WIDTH   [UIScreen mainScreen].bounds.size.width

@interface XTCellofCellForeveryone ()

@property (weak, nonatomic) IBOutlet UILabel *labelForRank;
@property (weak, nonatomic) IBOutlet UIImageView *singerImage;
@property (weak, nonatomic) IBOutlet UILabel *songName;

@property (weak, nonatomic) IBOutlet UIButton *playButton;
@property (weak, nonatomic) IBOutlet UILabel *singerName;

@property (weak, nonatomic) IBOutlet UILabel *playNumber;
@property (weak, nonatomic) IBOutlet UILabel *labelForHQ;
@property (weak, nonatomic) IBOutlet UILabel *labelForMV;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *songnameWidth;

@property (nonatomic,assign)double width;


@end


@implementation XTCellofCellForeveryone


- (void)passModel:(XCModelForEveryone *)model number:(NSInteger) rank {

    self.labelForRank.text = [NSString stringWithFormat:@"%ld", (long)rank];
    
    self.songName.text = model.name;
    
    CGRect rect = [self.songName.text boundingRectWithSize:CGSizeMake(0 , 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:17]} context:nil];

    NSLog(@"%f",rect.size.width);
    
    self.width = rect.size.width;
    
    [self.singerImage sd_setImageWithURL:[NSURL URLWithString:model.picUrl]];
    
     self.singerName.text = model.singerName;
    
    
    if (model.favorites >= 10000) {
        
        self.playNumber.text = [NSString stringWithFormat:@"%.1f万", round(model.favorites) / 10000 ];
        
    } else {
    
      self.playNumber.text = [NSString stringWithFormat:@"%ld", (long)model.favorites];
    

    }
}

- (void)awakeFromNib {
    
    
    self.labelForHQ.textColor = [UIColor greenColor];
      self.labelForHQ.layer.cornerRadius = 5;
    self.labelForHQ.layer.borderColor = [UIColor greenColor].CGColor;
    self.labelForHQ.layer.borderWidth = 1;
    self.labelForHQ.layer.masksToBounds = YES;
    
    self.labelForMV.textColor = [UIColor blueColor];
       self.labelForMV.layer.cornerRadius = 5;
    self.labelForMV.layer.borderColor = [UIColor blueColor].CGColor;
    self.labelForMV.layer.borderWidth = 1;
    self.labelForMV.layer.masksToBounds = YES;

    
}


-(void)layoutSubviews {
    [super layoutSubviews];
   

    if (self.width <= WIDTH * 0.42) {
         self.songnameWidth.constant = self.width;
    }else{
        
        self.songnameWidth.constant = WIDTH * 0.42;
        
    }
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
